from appium.webdriver.common.touch_action import TouchAction
from appium import webdriver
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import os
from base import Base

class Calender_addLearningTask(Base):
    def login(self):
        try:
            self.find_element((By.XPATH,"//*[contains(@text,'取消')]")).click()
            for i in range(2):
                self.swipe_left()
            sleep(2)
            self.swipe_right()
            self.find_element((By.XPATH,"//*[contains(@text,'跳过')]")).click()
            text=self.find_element((By.XPATH,"//*[contains(@text,'登录')]")).text
            assert text=='登录'
        except:
            try:
                text = self.find_element((By.XPATH, "//*[contains(@text,'登录')]")).text
                assert text == '登录'
            except:
                text = self.find_element((By.ID,'com.tal.kaoyan:id/home_fix_item_textview')).text
                assert text == '背单词'
    def click(self,locator):
        self.find_element(locator=locator).click()
    def left(self):
        self.swipe_left()
    def right(self):
        self.swipe_left()

if __name__ == '__main__':
    username = 'zdm12344321'
    password = 'a1234567'
    CaLT = Calender_addLearningTask()
    CaLT.find_element((By.ID, 'com.tal.kaoyan:id/login_email_edittext')).send_keys(username)
    CaLT.find_element((By.ID, 'com.tal.kaoyan:id/login_password_edittext')).send_keys(password)
    CaLT.click((By.ID, 'com.tal.kaoyan:id/login_login_btn'))
    CaLT.click((By.ID, 'com.tal.kaoyan:id/mainactivity_button_calendar'))
    CaLT.click((By.ID, 'com.tal.kaoyan:id/home_fix_item_img'))